//
//  Config.swift
//  SeeFM_Swift
//
//  Created by CBCT_MBP on 2021/6/25.
//

let kAppConfigInfo = "kAppConfigInfoKey"

import UIKit

class Config: HandyJSON {
    
    var serverInfo: ConfigServeInfo?
    
    var usedQuickGift: Bool?
    var shortVideoNotice: Bool?
    var shortVideoSlideNotice: Bool?
    var shortVideoAutoPush: Bool?
    
    
    required init() {
        usedQuickGift = false
        shortVideoNotice = false
    }
    
    class func appConfig() -> Config {

        let data = UserDefaults.standard.object(forKey: kAppConfigInfo)
        guard let d = data else { return Config.init()}
        let jsonData = String.init(data: d as! Data, encoding: .utf8)
        let config = Config.deserialize(from: jsonData)
        return config ?? Config.init()
    }
    
    class func updateConfig(_ updateClosure: ((_ config: Config)->())?) {
        let info = Self.appConfig()
        updateClosure?(info)
        UserDefaults.standard.setValue(info.toJSONString(), forKey: kAppConfigInfo)
    }

}

struct ConfigServeInfo: HandyJSON {
    
    var prefixImage: String?
    var prefixAvatar: String?
    var prefixPush: String?
    var prefixPull: String?
    var prefixIds: String?
    var prefixVideo: String?
    var carouselTime: String?
    var liveGap: String?
    var linkGap: String?
    var lifeCopyWriting: String?
    var programmePage: String?
    var hostPage: String?
    var channelPage: String?
    var programmeRoom: String?
    var lifeRoom: String?
    var giftVFX: String?
    var giftPrefix: String?
    var freeGift: String?
    var i_min_ver: String?
    var i_current_ver: String?
    var i_aud_ver: String?
    var i_upgrade_tips: String?
    var i_upgrade_ver: String?
    var problem_summary_open: String?
    var problem_summary_id: String?
    var introducer: String?
    var tagPage: String?
    
    var searchTestSign: String?
    var searchTestChannelSign: String?
    var navigationImage: String?
    var navigationUrl: String?
    var short_video_time: String?
    var max_duration: String?
    var min_duration: String?
    var user_min_duration: String?
    var user_max_duration: String?
    var send_time: String?
    var unicom_url: String?
    var video_limit: String?
    var view_time: String?
    var isCity: String?
    var voiceRoomPage: String?
    var refresh_tips: [String]?
    var is_need_login: Bool?
    var is_login_time: String?
    var force_login_word: String?
    var force_login_pic: String?
    var is_force_login: Bool?
    var new_host_rank_switch: Bool?
    var short_video_share: String?
    var off_http_dns: Bool?
    
}

struct ConfigGlobalInfo: HandyJSON {
    
    static var shared = ConfigGlobalInfo()
    
    var isLinking: Bool? = false
    var isBonusShowing: Bool? = false
    var isPushing: Bool? = false
    var fourGNotice: Bool? = true
    var unicomNotified: Bool? = false
    var insteadNotice: Bool? = true
    var timeDiff: Int? = 0
    var closedChatroomAdWidget: Bool? = false
    var isFreeUnicome: Bool? = false
    var isNotUShare: Bool? = false
    var idontCareMoney: Bool? = false
    var msgRecommendDot: Bool? = false
    
}
